package com.sanploy.manage.conf.filter;

import com.sanploy.common.enums.Meta;
import com.sanploy.common.vo.BaseException;
import com.sanploy.common.vo.BaseResp;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * Created by yingzhi zhu on 2017/9/17.
 * @author yingzhi zhu
 * 对返回的异常进行统一处理
 */
@RestControllerAdvice
public class ExceptionAdvice {


    /**
     * 自定义BaseException 进行处理
     * @param e
     * @return
     */
    @ExceptionHandler(BaseException.class)
    public BaseResp baseExceptionHandler(BaseException e){
        e.printStackTrace();
        BaseResp baseResp = new BaseResp();
        baseResp.setMeta(e.getMeta());
        return baseResp;
    }

    /**
     * 除了BaseException 所有异常的处理
     */
    @ExceptionHandler(Exception.class)
    public BaseResp otherExceptionHandler(Exception e){
        e.printStackTrace();
        BaseResp baseResp = new BaseResp();
        baseResp.setMeta(Meta.ServerError);
        return baseResp;
    }
}
